# -*- encoding: utf-8 -*-

import os
import sys
import subprocess
import re


def collect():
	filter_keys = ['Manufacturer', 'Serial Number', 'Product Name', 'UUID', 'Wake-up Type']
	raw_data = {}

	for key in filter_keys:
		try:
			cmd = "dmidecode -t system | grep '%s'" % key
			cmd_result = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout.readlines()
			cmd_res = cmd_result[0].decode().strip()

			res_to_list = cmd_res.split(':')
			if len(res_to_list) > 1:
					raw_data[key] = res_to_list[1].strip()
			else:
					raw_data[key] = -1

		except Exception as e:
			print(e)
			raw_data[key] = -2

	data = {}
	data['manufactory'] = raw_data['Manufacturer']
	data['sn'] = raw_data['Serial Number']
	data['model'] = raw_data['Product Name']
	data['uuid'] = raw_data['UUID']
	data['wake_up_type'] = raw_data['Wake-up Type']

	return data